package org.grayrabbit.cms.rpc;

import org.grayrabbit.cloud.core.biz.BizResult;
import org.grayrabbit.cloud.core.biz.ObjectArgument;
import org.grayrabbit.cloud.core.module.ModuleException;
import org.grayrabbit.cloud.core.module.NoSuchModuleException;
import org.grayrabbit.cms.api.vo.LoginBean;
import org.grayrabbit.cms.constant.RpcCode;
import org.grayrabbit.cms.service.api.LoginApi;
import org.grayrabbit.cms.util.RpcCmsFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RpcLogin implements LoginApi {
	private static final Logger log = LoggerFactory.getLogger(RpcLogin.class);
	
	
	public LoginBean login(String username, String password) {
		ObjectArgument argument = new ObjectArgument(RpcCode.MODULE_LOGIN);
		argument.putParam("username", username);
		argument.putParam("password", password);
		argument.putMethodName("login");
		
		try {
			
			RpcCmsFactory factory = RpcCmsFactory.getInstance();
			BizResult result =  factory.invoke(argument);
			return (LoginBean) result.getResult();
		}catch (NoSuchModuleException e) {
			log.error("没有这个模块", e);
		} catch (ModuleException e) {
			log.error("模块异常", e);
			return null;
		}catch(Exception e){
			
		}
		return null;
	}
}
